define(function(require, exports){
	var $ = require('jquery');
	var pubjs = require('pubjs');
	var util = require('util');
	var base = require('../modules/basePopwin').base;

	var STATUS_MAP ={
		'OPEN': 1,
		'PAUSE': 2
	}

	// 设置名称与状态
	var SetName = base.extend({
		init: function(config){
			config = pubjs.conf(config, {
				'layout': {
					"title": LANG('设置名称与状态')
				},
				'view_model': {
					// 推广组名称
					'name': '',
					// 推广组状态
					'status': STATUS_MAP.OPEN,

					'status_open': STATUS_MAP.OPEN,
					'status_pause': STATUS_MAP.PAUSE
				}
			});

			this.Super('init', arguments);
		}
		,afterBuild: function(){
			var el = this.getDOM();
			el.append($([
				'<div>',
					'<div class="M-formConGroup">',
						'<label class="group-label">'+ LANG('推广组名称：') + '</label>',
						'<div class="group-content">',
							'<input class="w250" ms-duplex="name" type="text"/>',
						'</div>',
					'</div>',
					'<div class="M-formConGroup">',
						'<label class="group-label">' + LANG('推广组状态：') + '</label>',
						'<div class="group-content">',
							'<label class="cur_p">',
								'<input ms-value="status_open" type="radio" ms-duplex-text="status"/>',
								LANG('开启'),
							'</label>',
							'<label class="cur_p ml15">',
								'<input ms-value="status_pause" type="radio" ms-duplex-text="status"/>',
								LANG('暂停'),
							'</label>',
						'</div>',
					'</div>',
				'</div>'
			].join('')));

			this.buildFromTemplate();
		}
		,afterBuildTemplate: function(){
			this.defaultName();
		}
		,defaultName: function(){
			var vm = this.vm.$;
			var currentTime = util.date('YmdHis');
			vm.name = LANG('新建推广组_') + currentTime;
			return this;
		}
		,getData: function(){
			var vm = this.vm.$;
			var data = {};
			data.Name = vm.name;
			data.Status = vm.status;

			return data;
		}
		,setData: function(data){
			var vm = this.vm.$;
			vm.name = data.Name;
			vm.status = data.Status;
			return this;
		}
		,validate: function(data){
			if (!data.Name) {
				pubjs.alert(LANG('请输入推广组名称！'));
				return false;
			}
			else if (data.Name.length > 50) {
				pubjs.alert(LANG('推广组名称不得超过 50 个字符'));
				return false;
			}

			return true;
		}
		,reset: function(){
			this.vm.reset();
			this.defaultName();
			return this;
		}
	});

	exports.setName = SetName;

	// 设置差异出价
	var SetDifferencesDid = base.extend({
		init: function(config){
			config = pubjs.conf(config, {
				'layout': {
					"title": LANG('设置差异出价')
				},
				'view_model': {
					'unit': LANG('元')
				}
			});

			this.Super('init', arguments);
		}
		,afterBuild: function(){
			var el = this.getDOM();
			el.append($([
				'<div class="M-formConGroup">',
					'<label class="group-label">' + LANG('差异出价：') + '</label>',
					'<div class=""group-content>',
						'<span pub-name="type" pub-mod="@base/common/drop.drop"/>',
						'<span class="ml10" pub-name="value" pub-mod="@base/common/input.text"/>',
						'<span class="ml10" ms-text="unit"/>',
					'</div>',
				'</div>'
			].join('')));

			var typeItems = [
				{name: LANG('值'), id: 0},
				{name: LANG('比例'), id: 1}
			];

			this.buildFromTemplate({
				value: {
					'width': 125,
					'placeholder': '0.00'
				},
				type: {
					'width': 110,
					'options': typeItems,
					'hasSearch': false,
					'value': 0
				}
			});
		}
		,onDropChange: function(ev){
			var vm = this.vm.$;
			var name = ev.param.name;
			switch (name){
				case '值':
					vm.unit = '元';
					break;
				case '比例':
					vm.unit = '%';
					break;
			}
		}
		,getData: function(){
			var cs = this.$;
			var data = {
				'Type': cs.type.getValue('id'),
				'Value': cs.value.getValue()
			};

			return data;
		}
		,setData: function(data){
			var cs = this.$;
			cs.type.setValue(data.Type);
			cs.value.setValue(data.Value);

			return this;
		}
		,reset: function(){
			var cs = this.$;
			cs.type.reset();
			cs.value.reset();

			return this;
		}
	});

	exports.setDifferencesDid = SetDifferencesDid;

	// 设置预算
	var SetBudget = base.extend({
		init: function(config){
			config = pubjs.conf(config, {
				'layout': {
					"title": LANG('设置预算')
				},
				'view_model': {
					// 是否显示历史总消耗等
					'showHistory': false,
					// 总消耗
					'cost': 0,
					// 总展示
					'impressions': 0,
					// 总点击
					'clicks': 0
				}
			});

			this.Super('init', arguments);
		}
		,afterBuild: function(){
			this.Super('afterBuild', arguments);
			var self = this;
			var el = self.getDOM();
			el.append($([
				'<div class="mt20">',
					'<div class="alert a-is-primary" ms-visible="showHistory">',
						'<span>'+ LANG('历史总消耗：') + '</span>',
						'<span class="mr5">{{ cost }}</span>',
						'<span class="mr10">'+ LANG('元，') + '</span>',
						'<span>'+ LANG('总展示：') + '</span>',
						'<span class="mr5">{{ impressions }}</span>',
						'<span class="mr10">'+ LANG('次，') + '</span>',
						'<span>'+ LANG('总点击：') + '</span>',
						'<span class="mr5">{{ clicks }}</span>',
						'<span>'+ LANG('次') + '</span>',
					'</div>',
					'<div class="mt20" pub-name="totalLimit" pub-mod="plan/modules/limit.planBudget"/>',
					'<div class="mt20" pub-name="dailyLimit" pub-mod="plan/modules/limit.planBudget"/>',
				'</div>'
			].join('')));
			el.find('.alert').css({'color': 'black'});

			self.buildFromTemplate({
				totalLimit: {
					'view_model': {
						'data': [
							{value: '0.00', field: 'Budget', text: LANG('总预算：'),unit: LANG('元'), validRegex: /[^0-9\s]/},
							{value: '0', field: 'Impression', text: LANG('总展示：'),unit: LANG('千次'), validRegex: /[^0-9\s]/},
							{value: '0', field: 'Click', text: LANG('总点击：'),unit: LANG('次'), validRegex: /[^0-9\s]/}
						]
					}
				},
				dailyLimit: {
					'view_model': {
						'data': [
							{value: '0.00', field: 'Budget', text: LANG('每日预算：'),unit: LANG('元'), validRegex: /[^0-9\s]/},
							{value: '0', field: 'Impression', text: LANG('每日展示：'),unit: LANG('千次'), validRegex: /[^0-9\s]/},
							{value: '0', field: 'Click', text: LANG('每日点击：'),unit: LANG('次'), validRegex: /[^0-9\s]/}
						]
					}
				}
			});
		}
		,setParam: function(param){
			var vm = this.vm.$;
			var history = true;
			vm.showHistory = history;
			if (history) {
				vm.cost = param.consumption;
				vm.impressions = param.totalShow;
				vm.clicks = param.totalClick;
				return this;
			}
			else {
				return this;
			}
		}
		,setData: function(data) {
			var cs = this.$;
			var vm = this.vm.$;
			cs.totalLimit.setData(data.totalLimit);
			cs.dailyLimit.setData(data.dailyLimit);
			
			// 显示历史数据
			if (data.showHistory)
			{
				var history = data.history || {};
				vm.showHistory = data.showHistory;
				vm.cost = history.cost || 0;
				vm.impressions = history.impressions || 0;
				vm.clicks = history.clicks || 0;
			}
			return this;
		}
		,getData: function(){
			var cs = this.$;
			var data = {};
			data.totalLimit = arrToMap(cs.totalLimit.getData());
			data.dailyLimit = arrToMap(cs.dailyLimit.getData());
			
			function arrToMap(arr)
			{
				var ret = {};
				util.each(arr, function(item)
				{
					ret[item.field] = +item.value;
				});
				return ret;
			}

			return data;
		}
		,reset: function(){
			var cs = this.$;
			this.vm.reset();
			cs.totalLimit.reset();
			cs.dailyLimit.reset();

			return this;
		}
	});

	exports.setBudget = SetBudget;

	// 设置频次
	var SetFrequency = base.extend({
		init: function(config){
			config = pubjs.conf(config, {
				'layout': {
					"title": LANG('设置频次')
				},
				'view_model': {
					'status': 0,
					// 是否显示频次控制
					'showFrequency': false
				}
			});

			this.Super('init', arguments);
		}
		,afterBuild: function(){
			var self = this;
			var el = self.getDOM();
			el.append($([
				'<div>',
					'<div class="M-formConGroup">',
						'<label class="group-label">' + LANG('频次控制：') + '</label>',
						'<div class="group-content">',
							'<div class="M-formSectionItem">',
								'<label class="cur_p">',
									'<input type="radio" ms-duplex-text="status" ms-value="0">',
									'<span class="ml10">' + LANG('不限') + '</span>',
								'</label>',
								'<label class="cur_p">',
									'<input type="radio" ms-duplex-text="status" ms-value="1">',
									'<span class="ml10">'+ LANG('指定频次') + '</span>',
								'</label>',
							'</div>',
						'</div>',
						'<div ms-visible="status!=0" class="M-formSectionItem mt10 ml10">',
							'<span pub-name="frequency" pub-mod="campaign/modules/newFrequency.planFrequency"/>',
						'</div>',
					'</div>',
				'</div>'
			].join('')));

			self.buildFromTemplate();
		}
		,getData: function(){
			var vm = this.vm.$;
			var data = {};
			data.status = +vm.status;
			if (data.status === 1) {
				data.frequency = this.$.frequency.getData();
			}
			else {
				data.frequency = [];
			}

			return data;
		}
		,setData: function(data){
			var vm = this.vm.$;
			vm.status = data.status;
			this.$.frequency.setData(data.frequency);

			return this;
		}
		,reset: function(){
			this.vm.reset();
			this.$.frequency.reset();

			return this;
		}
	});

	exports.setFrequency = SetFrequency;

	// 设置其他
	var SetOthers = base.extend({
		init: function(config){
			config = pubjs.conf(config, {
				'tplFile': '/tpl/campaign/setPromoteGroup/setOthers.tpl',
				'layout': {
					"title": LANG('设置其他')
				},
				'view_model': {
					// 自定义ID
					'CustomId': '',
					// 投放速度
					'GovernorStatus': 0,
					'ThirdMonitor': {
						// 三方曝光检测
						'Exposure': '',
						// 三方点击检测
						'Click': ''
					},
					// 品牌保护
					'BrandSafeUrl': ''
				}
			});

			this.Super('init', arguments);
		}
		,afterBuild: function(){
			this.buildFromTemplate();
			// 点击查看宏定义触发的事件
			this.uiBind(this.getDOM().find('.viewMocro'), 'click', 'eventClickMacro')
		}
		,setData: function(data){
			var cs = this.$;
			var vm = this.vm.$;
			vm.CustomId = data.CustomId;
			vm.GovernorStatus = data.GovernorStatus;
			
			var ThirdMonitor = data.ThirdMonitor || {};
			vm.ThirdMonitor.Exposure = (ThirdMonitor.Exposure || []).join('\n');
			vm.ThirdMonitor.Click = (ThirdMonitor.Click || '').join('\n');

			vm.BrandSafeUrl = data.BrandSafeUrl;
			cs.campaignMonitor.setData(data.Monitor);
			cs.tag.setData(data.Label);

			return this;
		}
		,getData: function(){
			var cs = this.$;
			var vm = this.vm.$;
			var data = {
				'CustomId': vm.CustomId,
				'GovernorStatus': vm.GovernorStatus,
				'BrandSafeUrl': vm.BrandSafeUrl,
				'ThirdMonitor': {
					'Exposure': util.trim(vm.ThirdMonitor.Exposure).replace(/\r/g, '\n').split('\n'),
					'Click': util.trim(vm.ThirdMonitor.Click).replace(/\r/g, '\n').split('\n')
				},
				'Monitor': cs.campaignMonitor.getData(),
				'Label': cs.tag.getData()
			};

			return data;
		}
		,reset: function(){
			var cs = this.$;
			this.vm.reset();
			cs.campaignMonitor.reset();
			cs.tag.reset();

			return this;
		}
		,eventClickMacro: function(evt, elm){
			var desc = '<p目前支持以下的宏：</p><p>{adxid} 渠道 ID，例如是 Tanx 还是百度</p><p>{campaignid} 推广组 ID</p><p>{spotid} 广告位 ID</p><p>{width} 广告位宽度</p><p>{height} 广告位高度</p><p>{ctpid} 创意包 ID</p><p>{ldpid} 落地页 ID</p><p>{refh} 来源域名</p>';
			var tip = this.get('customTip');
			if(!tip){
				this.createAsync('customTip', '@base/tip.base', {
					anchor: $(elm),
					width: 300,
					height: 200,
					pos: 'mr',
					offsetY: 60,
					offsetX: 10,
					hasArrow: false,
					autoHide: 'click'
				},function(mod){
					if(mod){
						mod.setData(desc);
					}
				});
			}else{
				tip.show();
				tip.setData(desc);
			}
		}
	});

	exports.setOthers = SetOthers;

	// 设置出价
	var SetPrice = base.extend({
		init: function(config){
			config = pubjs.conf(config, {
				'layout': {
					'title': LANG('设置出价')
				},
				'view_model': {
					// 目标名字
					'targetName': LANG('目标CPM：'),
					// 目标值
					'targetValue': '',
					// 目标单位
					'targetUnit': LANG('元/千次曝光'),
					// 最高CPM的值
					'topCPM': '',
					// 是否显示最高CPM
					'showTopCPM': true
				}
			});

			// 显示最高CPM的锁
			this.$showTopCPM = true;
			this.Super('init', arguments);
		}
		,afterBuild: function(){
			var el = this.getDOM();
			el.append($([
				'<div>',
					'<div class="M-formConGroup">',
						'<label class="group-label">' + LANG('出价方式：') + '</label>',
						'<div class="group-content">',
							'<div pub-name="bidRadios" pub-mod="@base/common/input.radioGroup"/>',
						'</div>',
					'</div>',
					'<div class="M-formConGroup">',
						'<label class="group-label" ms-text="targetName"/>',
						'<div class="group-content">',
							'<input type="text" ms-duplex="targetValue"/>',
							'<span class="ml10" ms-text="targetUnit"/>',
						'</div>',
					'</div>',
					'<div class="M-formConGroup">',
						'<label class="group-label">' + LANG('算法模型：') + '</label>',
						'<div class="group-content">',
							'<span pub-name="algorithmMod" pub-mod="@base/common/drop.drop"/>',
							'<span class="ml10" pub-name="algorithmTip" pub-mod="@base/tip.desc"/>',
						'</div>',
					'</div>',
					'<div class="M-formConGroup" ms-visible="showTopCPM">',
						'<label class="group-label">' + LANG('最高CPM：') + '</label>',
						'<div class="group-content">',
							'<input ms-duplex="topCPM" type="text"/>',
							'<span class="ml10">' + LANG('元/千次曝光') + '</span>',
						'</div>',
					'</div>',
				'</div>'
			].join('')));

			// 出价方式候选项配置
			var CHARGE_TYPE_OPTS = [
				{text: LANG("竞价CPM"), value: 0},
				{text: LANG("CPA优化"), value: 1},
				{text: LANG("CPC优化"), value: 2},
				{text: LANG("固定CPC"), value: 3}
			];

			this.buildFromTemplate({
				bidRadios: {
					'data': CHARGE_TYPE_OPTS,
					'value': 0
				},
				algorithmMod: {
					'width': 120,
					'hasSearch': false,
					'options': [
						{name: LANG('模型A'), id: 1},
						{name: LANG('模型B'), id: 2},
					],
					'value': 1
				},
				algorithmTip: {
					data: LANG('算法优化出价使得最终结果会尽可能接近目标值（建议）')
				}
			});
		}
		,onDropChange: function(ev){
			var cs = this.$;
			var vm = this.vm.$;
			var name = ev.param.name;
			switch (name){
				case '模型A':
					if (this.$showTopCPM) {
						vm.showTopCPM = true;
					}
					cs.algorithmTip.setConfig('data', LANG('算法优化出价使得最终结果会尽可能接近目标值（建议）'));
					break;
				case '模型B':
					vm.showTopCPM = false;
					cs.algorithmTip.setConfig('data', LANG('不优化出价，最终结果就是目标值（不建议）'));
					break;
			}
		}
		,onRadioChange: function(ev){
			var cs = this.$;
			var vm = this.vm.$;
			var name = ev.name;
			var param = ev.param;

			var algorithmModItems = [
				{name: LANG('模型A'), id: 1},
				{name: LANG('模型B'), id: 2},
			];

			var algorithmModItem = [
				{name: LANG('模型A'), id: 1}
			];

			if (name === 'bidRadios') {
				// 改变选项，重置对应的内容
				this.resetPart();

				if (cs.algorithmMod) {
					if (param === 0) {
						this.$showTopCPM = true;
						vm.showTopCPM = true;
						vm.targetUnit = LANG('元/千次曝光');
						cs.algorithmMod.setData(algorithmModItems);
					}
					else {
						this.$showTopCPM = false;
						vm.showTopCPM = false;
						vm.targetUnit = LANG('元');
						cs.algorithmMod.setData(algorithmModItem);
					}
				}

				switch (param){
					case 0:
						vm.targetName = LANG('目标CPM：');
						break;
					case 1:
						vm.targetName = LANG('目标CPA：');
						break;
					case 2:
						vm.targetName = LANG('目标CPC：');
						break;
					case 3:
						vm.targetName = LANG('结算CPC：');
						break;
				}
			}
		}
		,getData: function(){
			var cs = this.$;
			var vm = this.vm.$;
			var data = {
				'Way': +cs.bidRadios.getValue(),
				'Price': +vm.targetValue,
				'OptimizeMode': +cs.algorithmMod.getValue('id'),
				'TopCpm': 0
			};

			// cpm出价和模型A，才有最高cpm出价
			if ((data.Way == 0) && (data.OptimizeMode == 1))
			{
				data.TopCpm = +vm.topCPM || 0;
			}

			return data;
		}
		,setData: function(data){
			var cs = this.$;
			var vm = this.vm.$;
			cs.bidRadios.setValue(data.Way);
			vm.targetValue = data.Price;
			cs.algorithmMod.setValue(data.OptimizeMode);
			vm.topCPM = data.TopCpm;

			return this;
		}
		// reset除了出价方式外的值
		,resetPart: function(){
			var cs = this.$;
			if (cs.algorithmMod)
			{
				cs.algorithmMod.reset();
			}

			return this;
		}
		,reset: function(){
			var cs = this.$;
			this.resetPart();
			this.vm.reset();			
			cs.bidRadios.setValue(0);

			return this;
		}
	});

	exports.setPrice = SetPrice;

	// 特殊条件
	var SetSpecialCondition = base.extend({
		init: function(config){
			config = pubjs.conf(config, {
				'layout': {
					"title": LANG('特殊条件')
				}
			});

			this.Super('init', arguments);
		}
		,afterBuild: function(){
			var el = this.getDOM();
			el.append($([
				'<div class="mt30" pub-mod="campaign/modules/spotAddon.base" pub-name="spotAddon">',
			].join('')));

			this.buildFromTemplate();
		}
		,getData: function(){
			return this.$.spotAddon.getData();
		}
		,setData: function(data){
			this.$.spotAddon.setData(data);
			return this;
		}
		,reset: function(){
			this.$.spotAddon.reset();
			return this;
		}
	});

	exports.setSpecialCondition = SetSpecialCondition;
	
	
	// 优化策略
	var SetOptimizeStrategy = base.extend({
		init: function(config){
			var COMMON_OPTS = [
				{'id': 0, 'name': LANG('智能优化')},
				{'id': 1, 'name': LANG('按点击优化')},
				{'id': 2, 'name': LANG('按注册优化')}
			];
			var def_type = 0;
			
			config = pubjs.conf(config, {
				'layout': {
					'title': LANG('设置出价')
				},
				'vModel': {
					'sweetyOpts': COMMON_OPTS.concat({'id': 3, 'name': LANG('人工分配')}),
					'whiskyOpts': COMMON_OPTS.concat({'id': 3, 'name': LANG('人工分配')}),
					'spotOpts': COMMON_OPTS,
					
					'impressionOpts': [
						{'id': 0, 'name': LANG('随机')},
						{'id': 1, 'name': LANG('循环')},
						{'id': 2, 'name': LANG('轮显')}
					],
					
					'sweetyOptimizeType': def_type,
					'whiskyOptimizeType': def_type,
					'spotOptimizeType': def_type,
					'impressionOptimizeType': def_type
				}
			});
			
			// 缓存落地页创意包数据
			this.$sweetys = [];
			this.$whiskys = [];

			this.Super('init', arguments);
		}
		,afterBuild: function(){
			var el = this.getDOM();
			el.append($([
				'<div>',
					'<div class="fs15">'+ LANG('流量分配优化策略：') + '</div>',
					'<div class="M-formConGroup">',
						'<label class="group-label">' + LANG('创意包：') + '</label>',
						'<div class="group-content">',
							'<div>',
								'<label v-for="item in sweetyOpts" class="mr15">',
									'<input type="radio" v-bind:value="item.id" v-model="sweetyOptimizeType"/>',
									'{{item.name}}',
								'</label>',
							'</div>',
							'<div v-show="sweetyOptimizeType==3" pub-name="sweetyRatio" pub-mod="modules/scale.base" class="optimiza-ratio mb30 w500 mt10" />',
						'</div>',
					'</div>',
					
					'<div class="M-formConGroup">',
						'<label class="group-label">' + LANG('落地页：') + '</label>',
						'<div class="group-content">',
							'<div>',
								'<label v-for="item in whiskyOpts" class="mr15">',
									'<input type="radio" v-bind:value="item.id" v-model="whiskyOptimizeType"/>',
									'{{item.name}}',
								'</label>',
							'</div>',
							'<div v-show="whiskyOptimizeType==3" pub-name="whiskyRatio" pub-mod="modules/scale.base" class="optimiza-ratio mb30 w500 mt10" />',
						'</div>',
					'</div>',
					
					'<div class="M-formConGroup">',
						'<label class="group-label">' + LANG('广告位：') + '</label>',
						'<div class="group-content">',
							'<div>',
								'<label v-for="item in spotOpts" class="mr15">',
									'<input type="radio" v-bind:value="item.id" v-model="spotOptimizeType"/>',
									'{{item.name}}',
								'</label>',
							'</div>',
						'</div>',
					'</div>',
					
					'<div class="fs15">'+ LANG('创意包展示策略：') + '</div>',
					
					'<div class="M-formConGroup">',
						'<label class="group-label">' + LANG('展示顺序：') + '</label>',
						'<div class="group-content">',
							'<div>',
								'<label v-for="item in impressionOpts" class="mr30">',
									'<input type="radio" v-bind:value="item.id" v-model="impressionOptimizeType"/>',
									'{{item.name}}',
								'</label>',
							'</div>',
						'</div>',
					'</div>',
				'</div>'
			].join('')));
			

			this.buildFromTemplate({
			
			});
			
			
			this.vm.mount();
		}
	
		,getData: function(){
			var data = this.vm.getCopy();
			var ret = {};
			
			// 落地页
			ret.WhiskyOptimizeType = +data.whiskyOptimizeType || 0;
			if (ret.WhiskyOptimizeType == 3)
			{
				ret.WhiskyRatio = this.$.whiskyRatio.getData();
			}
			// 创意包
			ret.SweetyOptimizeType = +data.sweetyOptimizeType || 0;
			if (ret.SweetyOptimizeType == 3)
			{
				ret.SweetyRatio = this.$.sweetyRatio.getData();
			}
			// 广告位
			ret.SpotOptimizeType = +data.spotOptimizeType || 0;

			// 展示
			ret.ImpressionOptimizeType = +data.impressionOptimizeType || 0;
			
			return ret;
		}
		,setData: function(data)
		{
			var cs = this.$;	
			var vm = this.vm.$;
			
			this.$sweetys = data.sweetys || [];
			this.$whiskys = data.whiskys || [];
			
			// 落地页
			vm.whiskyOptimizeType = +data.WhiskyOptimizeType || 0;
			var whiskyRatio = [];
			if (vm.whiskyOptimizeType == 3 && !util.isEmptyObject(data.WhiskyRatio))
			{
				whiskyRatio = [];
				util.each(data.whiskys, function(whisky)
				{
					var tmp = {};
					tmp.id = whisky._id;
					tmp.text = whisky.Name;
					tmp.value = data.WhiskyRatio[whisky._id];
					whiskyRatio.push(tmp);
				});
				cs.whiskyRatio.setData(whiskyRatio);
			}
			//如果不是自定义，应该要默认的按照落地页数量平均分配, 方便由其他选项切换过去的时候显示
			else if (data.whiskys && data.whiskys.length)
			{
				whiskyRatio = [];
				var whiskyLength = data.whiskys.length;
				util.each(data.whiskys, function(whisky)
				{
					var tmp = {};
					tmp.id = whisky._id;
					tmp.text = whisky.Name;
					tmp.value = 100 / whiskyLength;
					whiskyRatio.push(tmp);
				});

				this.$.whiskyRatio.setData(whiskyRatio);
			}

			// 创意包
			var sweetyRatio = [];
			vm.sweetyOptimizeType = +data.SweetyOptimizeType || 0;
			if (vm.sweetyOptimizeType == 3 && !util.isEmptyObject(data.SweetyRatio))
			{
				sweetyRatio = [];
				var whiskyLength = data.whiskys.length;
				util.each(data.sweetys, function(sweety)
				{
					var tmp = {};
					tmp.id = sweety._id;
					tmp.text = sweety.Name;
					tmp.value = data.SweetyRatio[sweety._id];
					sweetyRatio.push(tmp);
				});
				cs.sweetyRatio.setData(sweetyRatio);
			}
			//如果不是自定义，应该要默认的按照创意包数量平均分配, 方便由其他选项切换过去的时候显示
			else if (data.sweetys && data.sweetys.length)
			{
				sweetyRatio = [];
				var sweetyLength = data.sweetys.length;
				util.each(data.sweetys, function(sweety)
				{
					var tmp = {};
					tmp.id = sweety._id;
					tmp.text = sweety.Name;
					tmp.value = 100 / sweetyLength;
					sweetyRatio.push(tmp);
				});

				this.$.sweetyRatio.setData(sweetyRatio);
			}
			

			// 广告位
			vm.spotOptimizeType = +data.SpotOptimizeType || 0;
			
			// 展示顺序
			vm.impressionOptimizeType = +data.ImpressionOptimizeType || 0;

			return this;
		}
		,reset: function(){
			this.vm.reset();
			this.$.sweetyRatio.reset();
			this.$.whiskyRatio.reset();
			return this;
		}
	});
	
	exports.setOptimizeStrategy = SetOptimizeStrategy;
});